<template>
  <div
      class="userHead"
      :class="sexClass"
      :style="{
        width:size?size+'px':'36px',
        height:size?size+'px':'36px',
      }"
  >
    <template v-if="src">
      <img :src="src" alt="" class="img">
    </template>
    <template v-else>
      <p>{{name.substring(0,1)}}</p>
    </template>
  </div>
</template>
<script>
export default {
  name: 'UserHead',
  //获取父级数据
  props:[
      'src',
      'name',
      'sex',
      'size',
  ],
  //引用组件
  components: {

  },
  //当前数据
  data () {
    return{

    }
  },
  //生命周期
  mounted() {

  },
  //计算属性
  computed:{
    sexClass(){
      let sexClass=''
      if (!this.src){
        if (this.sex==='男'){
          sexClass='man'
        }else  if (this.sex==='女'){
          sexClass='girl'
        }else{
          sexClass='man'
        }
      }
      return sexClass
    }
  },
  //方法
  methods:{

  },
}
</script>

<style lang="scss" scoped>
.userHead{
  border-radius: 100px;
  overflow: hidden;
  border: 1px #fff solid;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #fff;
  position: relative;
  background: #f2f2f2;
  .img{
    position: absolute;
    left: 50%;
    top:50%;
    transform:translate(-50%,-50%);
    max-width: 100%;
    max-height: 100%;
    pointer-events:none;
  }
  &.girl{
    background-color: #fb7fb7;
    color: #fff;
  }
  &.man{
    background-color: #3967FF;
    color: #fff;
  }
  p{
    font-weight: normal;
    font-size: 14px;
    &.small{
      transform:scale(0.8);
    }
  }
}
</style>
